#include "html.h"

namespace html { namespace dom {
  /// @brief global symbol table
  /// to make it thread safe
  symbol symbol_table::getadd(const string& _str) {
    // brief search the symbol table for the given string identifier
    str2id::const_iterator it = get_symbol_table().str_to_id_.find(_str);
    // if found, return the symbol id
    if (it != get_symbol_table().str_to_id_.end()) 
      return it->second;
    // create a new id by creating a new string pointer that holds the 
    // string identifier
    symbol::id id = new string(_str);
    // store the id in the symbol table and return it
    return get_symbol_table().str_to_id_[_str] = id;
  }
  symbol symbol_table::find(const string& _str) {
    // brief search the symbol table for the given string identifier
    str2id::const_iterator it = get_symbol_table().str_to_id_.find(_str);
    // if found, return the symbol id
    if (it != get_symbol_table().str_to_id_.end()) 
      return it->second;
    // return invalid symbol
    return symbol::nil();
  }
  /// @brief basic symbol 'id' for id attributes
  symbol id_symbol = symbol("id");
  /// @brief basic symbol 'class' for class attributes
  symbol class_symbol = symbol("class");
  /// @brief basic symbol '--' for html comment tags names
  symbol comment_symbol = symbol("--");
} }
